package logic

import (
	"context"
	"goods-guru/models/mysql"

	"goods-guru/goodrpc/goodrpc"
	"goods-guru/goodrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodShowLogic {
	return &GoodShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodShowLogic) GoodShow(in *goodrpc.GoodShowRequest) (*goodrpc.GoodShowResponse, error) {
	// todo: add your logic here and delete this line
	var good mysql.Good
	mysql.DB.Table("goods").
		Where("good.Id=?", in.GoodId).
		Select("good.*,classes.name as class_name,brands.name as brand_name").
		Joins("left join classes on classes.Id = good.class_id").
		Joins("left join brands on brands.Id = good.brand_id").
		Find(&good)
	return &goodrpc.GoodShowResponse{
		Title:     good.Title,
		ClassName: string(good.ClassId),
		BrandName: string(good.BrandId),
	}, nil
}
